<template>
  <div id="headerContainer">
    <div id="nav">
      <!-- menu搜索与展开 -->
      <el-button
        plain
        icon="el-icon-menu"
        size="mini"
        @click="handleMenu"
      ></el-button>
      <!-- 面包屑 -->
      <el-breadcrumb separator="/">
        <el-breadcrumb-item
          v-for="item in tags"
          :key="item.path"
          :to="{ path: item.path }"
          >{{ item.title }}</el-breadcrumb-item
        >
      </el-breadcrumb>
      <!-- 文档入口 -->
      <!-- 用户中心 -->
      <el-dropdown>
        <div class="block">
          <el-avatar :src="user.avatar"></el-avatar>
          <i class="el-icon-caret-bottom el-icon--right"></i>
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/userInfo">
            <el-dropdown-item> 个人中心 </el-dropdown-item>
          </router-link>
          <!-- <el-dropdown-item command="个人中心">个人中心</el-dropdown-item> -->
          <span style="display: block" @click="open">
            <el-dropdown-item command="退出登录" divided>
              退出登录
            </el-dropdown-item>
          </span>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <div id="tag">
      <!-- 面包屑切换tag -->
      <tag />
    </div>
  </div>
</template>

<script>
import { mapGetters, mapState } from "vuex";
import Tag from "@/components/Tag.vue";
// import store from "@/store";
export default {
  components: {
    Tag,
  },
  data() {
    return {};
  },
  methods: {
    handleMenu() {
      this.$store.commit("collapseMenu");
    },
    /* handleCommand(command) {
      this.$message("click on item " + command);
    }, */
    open() {
      this.$confirm("确定注销并退出系统吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.logout();
      });
    },
    logout() {
      this.$store.dispatch("logout").then(() => {
        location.reload();
      });
    },
  },
  computed: {
    ...mapState({
      tags: (state) => state.tab.tabsList,
    }),
    ...mapGetters(["user"]),
  },
};
</script>

<style scoped>
#nav {
  /* width: calc(100% - 220px); */
  width: 100%;
  height: 50px;
  background-color: #fff;
  line-height: 45px;
  border-bottom: 1px solid rgb(238, 236, 236);
}
#tag {
  /* width: calc(100% - 220px); */
  width: 100%;
  height: 35px;
  /* padding-left: 10px; */
  line-height: 35px;
  background-color: #fff;
}

.el-button {
  display: inline-block;
  margin-left: 10px;
  padding: 8px 10px;
}
.el-breadcrumb {
  display: inline-block;
  margin-left: 10px;
  color: black;
}

/* 个人中心 */
.el-dropdown {
  float: right;
  top: 5px;
  right: 20px;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
</style>